<template>
	<view class="u-p-b-100">
		<view class="flex-a-c u-m-30" v-for="(i,index) in mylist">
			<view class="">
				<u-input v-model="i.phone" >
					<u--text text="家长电话" slot="prefix" margin="0 3px 0 0" type="tips"></u--text>
				</u-input>
			</view>
			<view class="">
				<u-input v-model="i.studentName" >
					<u--text text="学生姓名" slot="prefix" margin="0 3px 0 0" type="tips"></u--text>
				</u-input>
			</view>
			<view class="u-m-l-20" style="color: red; flex-shrink: 0; " @click="del(index)">
				删除
			</view>
		</view>
		
		<view class="twobox" style="width: 100%;" >
			<view class="continue_add  u-radius-10" @click="addclick">
				继续添加
			</view>
			<view class="continue_add  u-radius-10" @click="submit">
				提交
			</view>
			
		</view>
		<view class="" style="width: 100%; height: 100rpx;">
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				mylist: [{phone:'',studentName:''}]
			}
		},
		onLoad() {

		},
		methods: {
			submit(){
				this.$api.post('/assistant/xStudent/batchCreate',
					this.mylist
				).then(res=>{
					if(res.code == 200){
						this.$toast('提交成功')
						setTimeout(()=>{
							this.$back()
						},1000)
					}
				})
			},
			del(index){
				if(this.mylist.length==1){
					return this.$toast('至少保留一个~')
				}
				this.mylist.splice(index,1)
			},
			addclick(){
				if(this.mylist.length==30){
					return this.$toast('至多添加30个~')
				}
				this.mylist.push({phone:'',name:''})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.twobox{
		display: flex;
		align-items: center;
		justify-content: space-around;
		width: 686rpx;
		
	}
	.continue_add{
		border: 1rpx solid #999;
		padding: 20rpx 10rpx;
		text-align: center;
		width: 200rpx;
	}
</style>